/*
Birth order data for Add Health
*/

clear

use "D:\Data\ProjData\SiblingOrder\OtherSamples\ADDHEALTH\ADDHEALTH.dta", clear

* Drop twin families
gen occ = 1
bysort FAMID CALCAGE3: egen nocc = sum(occ) if FAMID!=.
tab nocc
keep if nocc==1
drop occ nocc

* Number of siblings in the sample
drop SIBLINGS
gen occ = 1
bysort FAMID: egen SIBLINGS = sum(occ)
drop occ
replace SIBLINGS = . if FAMID == .

drop MALE
gen MALE = 1 if BIO_SEX == 1
replace MALE = 0 if BIO_SEX == 2

drop BIRTHORDER
gen BIRTHORDER = H1HR15

gen BIRTHORDER_DUM = .
replace BIRTHORDER_DUM = 0 if inrange(BIRTHORDER, 2, 100)
replace BIRTHORDER_DUM = 1 if BIRTHORDER==1


keep FAMID VOTE2000 BIRTHORDER BIRTHORDER_DUM MALE CALCAGE3


***Save file for pooled analysis
keep FAMID VOTE2000 BIRTHORDER BIRTHORDER_DUM MALE CALCAGE3
rename FAMID famid
rename VOTE2000 turnout
rename BIRTHORDER birthorder
rename BIRTHORDER_DUM birthorder_dum
rename MALE female
rename CALCAGE3 age
replace female = 1+female*-1
gen sample = "ADDHEALTH"
keep if inrange(birthorder, 1, 5)
qui: reghdfe turnout birthorder_dum female i.age, absorb(famid) cluster(famid)
sum turnout if e(sample)
gen turnout_average = r(mean)

save "D:\Data\ProjData\SiblingOrder\ReplicationAddHealth data 191128.dta", replace

